﻿@{
    Layout = "~/Areas/Mall/Views/Shared/_HomeLayout.cshtml";
    var memberLogin = ViewData["WebHeadMember"] as MemberLogin;
}

<link rel="stylesheet" href="~/Areas/Mall/css/head.css">
<link rel="stylesheet" href="~/Areas/Mall/css/login.css">
<div class="reinstall">
    <div class="top">
        <span>学习账户信息</span>
    </div>
    <div class="content">
        <input id="txtId" type="hidden" value="@(Model!=null?Model.Id:"")" />
        <input id="txtMemberId" type="hidden" value="@memberLogin.Id" />
        <div class="item">
            <span>手机号</span>
            <p><input id="txtUserName" type="text" class="input normal important" value="@(Model!=null?Model.UserName:"")"><span class="wrong"><img src="~/Areas/Mall/image/error.png" />请输入手机号</span></p>
        </div>
        <div class="item">
            <span>密码</span>
            <p><input id="txtPassWord" type="password" class="input normal important" value="@(Model!=null?Model.PassWord:"")"><span class="wrong"><img src="~/Areas/Mall/image/error.png" />请输入密码</span></p>
        </div>
        <div class="item">
            <span>姓名</span>
            <p><input id="txtRealName" type="text" class="input normal important" value="@(Model!=null?Model.RealName:"")"><span class="wrong"><img src="~/Areas/Mall/image/error.png" />请输入姓名</span></p>
        </div>
    </div>
    <div class="btn-wrap" style="position: static;">
        <input type="submit" value="提交保存" class="btn" onclick="save()">
        <input type="button" value="返回上一页" class="btn yellow" onclick="javascript:history.back(-1);">
    </div>
</div>

<script type="text/javascript" src="~/Areas/Mall/js/jquery-1.10.2.min.js"></script>
<script>
    $(".item .important").blur(function () {
        if ($(this).val()) {
            $(this).parent().find('.wrong').hide();
            $(this).removeClass('error')
        } else {
            $(this).parent().find('.wrong').show();
            $(this).addClass('error')
        }
    });

    //检测
    function check() {
        var retBool = true;
        //用户名
        var realName = $("#txtUserName").val();
        if (realName == undefined || realName == null || realName == "") {
            $("#txtUserName").parent().find('.wrong').show();
            $("#txtUserName").addClass('error');
            retBool = false;
        } else {
            $("#txtUserName").parent().find('.wrong').hide();
            $("#txtUserName").removeClass('error');
        }

        //密码
        var passWord = $("#txtPassWord").val();
        if (passWord == undefined || passWord == null || passWord == "") {
            $("#txtPassWord").parent().find('.wrong').show();
            $("#txtPassWord").addClass('error');
            retBool = false;
        } else {
            $("#txtPassWord").parent().find('.wrong').hide();
            $("#txtPassWord").removeClass('error');
        }

        //姓名
        var userName = $("#txtRealName").val();
        if (userName == undefined || userName == null || userName == "") {
            $("#txtRealName").parent().find('.wrong').show();
            $("#txtRealName").addClass('error');
            retBool = false;
        } else {
            $("#txtRealName").parent().find('.wrong').hide();
            $("#txtRealName").removeClass('error');
        }

        return retBool;
    }

    //保存
    function save() {
        if (check()) {
            var id = $("#txtId").val();
            var memberId = $("#txtMemberId").val();
            var userName = $("#txtUserName").val();
            var passWord = $("#txtPassWord").val();
            var realName = $("#txtRealName").val();
            var phone = $("#txtUserName").val();

            $.ajax({
                type: "POST",
                url: '@Url.Action("Save", "Student")',
                data: {
                    "Id": id,
                    "MemberId": memberId,
                    "UserName": userName,
                    "PassWord": passWord,
                    "RealName": realName,
                    "Phone": phone,
                    "Status": 1
                },
                success: function (res) {
                    if (res.Success) {
                        window.location.href = res.Data + '?r=' + (new Date()).valueOf();//直接跳转
                    } else {
                        alert(res.Message)
                    }
                }
            });
        }
    }
</script>